package com.cvpoc.service.impl;

import java.util.List;

import com.cvpoc.dto.ExperienceCompetenceDTO;
import com.cvpoc.dto.ExperienceDTO;
import com.cvpoc.exception.BusinessException;
import com.cvpoc.hibernate.dao.ExperienceDao;

public class ExperienceServiceImpl implements
		com.cvpoc.service.ExperienceService {
	// private CompetenceDao competenceDao;
	private ExperienceDao experienceDao;

	// public void setCompetenceDao(CompetenceDao competenceDao) {
	// this.competenceDao = competenceDao;
	// }

	public void setExperienceDao(ExperienceDao experienceDao) {
		this.experienceDao = experienceDao;
	}

	@Override
	public Integer createExperience(ExperienceDTO pExperienceDTO) {
		return experienceDao.createExperience(pExperienceDTO);
	}

	@Override
	public void deleteExperience(int pIdExperience) {
		ExperienceDTO experienceDTO = experienceDao
				.findExperienceById(pIdExperience);
		for (ExperienceCompetenceDTO experienceCompetenceDTO : experienceDTO
				.getExperienceCompetences()) {
			experienceDao.deleteExperienceCompetence(experienceCompetenceDTO);
		}
		experienceDao.deleteExperience(pIdExperience);
	}

	@Override
	public void updateExperience(ExperienceDTO pExperienceDTO) {
		experienceDao.updateExperience(pExperienceDTO);
	}

	@Override
	public List<ExperienceDTO> findListExperienceByIdCollaborateur(
			int idCollaborateur) throws BusinessException {
		List<ExperienceDTO> listeExperience = experienceDao
				.findExperiencesByCollaborateur(idCollaborateur);
		for (ExperienceDTO experienceDTO : listeExperience) {
			experienceDTO.setExperienceCompetences(experienceDao
					.findListExperienceCompetenceByIdExperience(experienceDTO
							.getId()));
		}
		return listeExperience;
	}

	@Override
	public void createExperienceCompetence(
			ExperienceCompetenceDTO pExperienceCompetenceDTO) {
		experienceDao.createExperienceCompetence(pExperienceCompetenceDTO);
	}

	@Override
	public void deleteExperienceCompetence(
			ExperienceCompetenceDTO pExperienceCompetenceDTO) {
		experienceDao.deleteExperienceCompetence(pExperienceCompetenceDTO);
	}

	@Override
	public void updateExperienceCompetence(
			ExperienceCompetenceDTO pExperienceCompetenceDTO) {
		experienceDao.updateExperienceCompetence(pExperienceCompetenceDTO);

	}
}
